package org.jeik.beackBeans.search;

import java.util.ArrayList;
import java.util.List;

import org.jeik.beackBeans.BeansBase;
import org.jeik.controllers.NavigationController;
import org.jeik.controllers.NavigationRule;
import org.jeik.search.SearchHandler;
import org.jeik.utils.Log;


/**
 * 
 * @author AAsha
 *
 */
public class SearchBean extends BeansBase {

	private static final long serialVersionUID = 1L;
	
	private String keyword;
	private List<SearchResultLink> resultLinks = new ArrayList<SearchResultLink>();
	
	/**
	 * 
	 */
	public void search(){
		
		if(keyword == null || keyword.isEmpty() || keyword.length() < 4){
			return;
		}
		
		SearchHandler sh = new SearchHandler();
		try {
			
			resultLinks.clear();
			
			resultLinks.addAll(sh.findPages(keyword));
			resultLinks.addAll(sh.findServices(keyword));
			
		} catch (Exception e) {
			Log.error(this, e.getMessage());
			e.printStackTrace();
		}
		
		NavigationController.navigate(NavigationRule.SEARCH_RESULTS);
		
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public List<SearchResultLink> getResultLinks() {
		return resultLinks;
	}

	public void setResultLinks(List<SearchResultLink> resultLinks) {
		this.resultLinks = resultLinks;
	}

}
